<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #div_parent {
            width: 600px;
            height: 500px;
            background-color: rgb(133, 169, 236);
        }
        
        #div_child {
            width: 300px;
            height: 250px;
            background-color: rgb(255, 195, 205);
        }
    </style>
</head>

<body>
    <div id="div_parent">
        父div
        <div id="div_child">子div</div>
    </div>
    <div>
        <ul>
            <li>apple</li>
            <li>banana</li>
            <li>watermelon</li>
        </ul>

    </div>
    <a href="www.baidu.com">百度</a>
    <script>
        window.onload = function() {


            let div_child = document.getElementById("div_child")
            let div_parent = document.getElementById("div_parent")

            div_child.addEventListener("click", (event) => {
                event.stopPropagation() //阻止传播
                console.log("div_child 被点击了")
            })
            div_parent.addEventListener("click", () => {
                console.log("div_parent 被点击了")
            })

            // document.querySelectorAll("ul li")[0].addEventListener("click",(event)=>{
            //     console.log(event.target.textContent)
            // })
            // document.querySelectorAll("ul li")[1].addEventListener("click",(event)=>{
            //     console.log(event.target.textContent)
            // })
            // document.querySelectorAll("ul li")[2].addEventListener("click",(event)=>{
            //     console.log(event.target.textContent)
            // })
            document.querySelectorAll("ul")[0].addEventListener("click", (event) => {
                console.log(event.target.innerText)
                    // console.log(event.target.remove)
            })
            document.getElementsByTagName("a")[0].addEventListener("click", (event) => {
                event.preventDefault()
                console.log("a元素被点击")
            })
        }
        console.log(document.body)
        document.body.addEventListener('click', () => {
            alert('你点击了页面！');
        });
    </script>
</body>

</html>